package fem2.strategies;

import fem2.Model;

public class NonAdaptiveNewtonRaphsonStrategy extends NewtonRaphsonStrategy {

	private double t = 0;
	private int step = 0;
	private double[] tArray = null;

	/**
	 * constructor
	 * 
	 * @param m
	 *            model
	 * @param nt
	 *            number of time steps
	 */
	public NonAdaptiveNewtonRaphsonStrategy(Model m, int nt) {
		super(m);
		setNumberOfTimeStep(nt);
	}

	/**
	 * special design constructor for linear analysis at time t0 (it's later
	 * used for free vibration analysis)
	 * 
	 * @param m
	 *            model
	 * @param nt
	 *            number of time steps
	 * @param t0
	 *            time at which linear static analysis perform
	 */
	public NonAdaptiveNewtonRaphsonStrategy(Model m, int nt, double t0) {
		super(m);
		setNumberOfTimeStep(nt);
		t = t0 - 1.0;
	}

	/**
	 * constructor
	 * 
	 * @param m
	 *            model
	 * @param tArray
	 *            time array
	 */
	public NonAdaptiveNewtonRaphsonStrategy(Model m, double[] tArray) {
		super(m);
		setNumberOfTimeStep(tArray.length);
		this.tArray = tArray;
	}

	@Override
	public double getNextTimeStep() {
		if (tArray == null) {
			t++;
		} else {
			t = tArray[step++];
		}
		return t;
	}

	@Override
	public double getCurrentTimeStep() {
		return t;
	}
}
